package com.baidb.gateway.reactive.configuration;

import com.baidb.gateway.reactive.filter.GrayReactiveLoadBalancerClientFilter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.gateway.config.LoadBalancerProperties;
import org.springframework.cloud.gateway.filter.ReactiveLoadBalancerClientFilter;
import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClients;
import org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author baidb
 * @date 2021/6/17.
 */
@LoadBalancerClients(defaultConfiguration = LoadBalancerClientsConfiguration.class)
@Configuration
@ConditionalOnProperty(value = "spring.cloud.loadbalancer.ribbon.enabled", havingValue = "false")
public class ReactiveLoadBanlancerConfiguration {

    @Bean
    @ConditionalOnMissingBean
    public ReactiveLoadBalancerClientFilter grayReactiveLoadBalancerClientFilter(
        LoadBalancerClientFactory clientFactory, LoadBalancerProperties properties) {
        return new GrayReactiveLoadBalancerClientFilter(clientFactory, properties);
    }

}
